package com.example.day23.ex02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @author 17976
 */
public class ComparatorDemo {
    public static void main(String[] args) {
        ArrayList<String> array = new ArrayList<String>();
        array.add("cccc");
        array.add("aa");
        array.add("b");
        array.add("ddd");
        System.out.println("排序前：" + array);
        Collections.sort(array, getComparator());
        System.out.println("排序后：" + array);
    }
    private static Comparator<String> getComparator() {

// return new Comparator<String>() {
// @Override
// public int compare(String s1, String s2) {
// return s1.length()-s2.length();
// }
// };

        return (s1, s2) -> s1.length() - s2.length();
    }
}
